/*** 
 * @Date: 2020-07-10 10:53:00
 * @LastEditors: leehave
 * @LastEditTime: 2020-08-17 18:25:37
 */
/***
 * @Date: 2020-07-10 10:53:00
 * @LastEditors: leehave
 * @LastEditTime: 2020-07-10 11:02:27
 */
import Vue from "vue";
import VueRouter from "vue-router";
import PageRouter from "./page";
import ViewsRouter from "./view";
import KejueRouter from "./kejue-router";
import Store from "../store";
Vue.use(VueRouter);
//创建路由
export const createRouter = () =>
  new VueRouter({
    mode: "history",
    base: process.env.NODE_DEV == 'development' ? '/' : '/',
    scrollBehavior(to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition;
      } else {
        if (from.meta.keepAlive) {
          from.meta.savedPosition = document.body.scrollTop;
        }
        return {
          x: 0,
          y: to.meta.savedPosition || 0
        };
      }
    },
    routes: [...PageRouter, ...ViewsRouter]
  });
const Router = createRouter();

KejueRouter.install(Vue, {
  router: Router,
  store: Store,
  keepAlive: false
});
console.log(process.env.NODE_DEV,'node env')
// Router.$KejueRouter.formatRoutes(Store.state.user.menuAll, true);
Router.addRoutes([...PageRouter, ...ViewsRouter]);
export function resetRouter() {
  const newRouter = createRouter();
  Router.matcher = newRouter.matcher; // reset router
  KejueRouter.install(Vue, {
    router: Router,
    store: Store,
    keepAlive: false
  });
}
export default Router;
